package com.xinyu.service.impl;

import com.xinyu.config.FileStorageProperties;
import com.xinyu.domain.Public;
import com.xinyu.domain.Reply;
import com.xinyu.mapper.ReplyMapper;
import com.xinyu.service.IReplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinyu.vo.BaseResult;
import com.xinyu.vo.ReplyRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  跟帖Service实现类
 * </p>
 *
 * @author: XinYu
 * @since 2025-02-17
 */
@Service
public class ReplyServiceImpl extends ServiceImpl<ReplyMapper, Reply> implements IReplyService {

    @Autowired
    private ReplyMapper replyMapper;
    @Autowired
    private FileStorageProperties fileStorageProperties; // 注入配置类
    @Override
    public BaseResult queryByPage(ReplyRequest replyRequest) {
        List<Reply> replyList = replyMapper.queryByPage(replyRequest);
        Integer replyCounts = replyMapper.replyCounts(replyRequest);

        for (Reply reply:replyList){
            if (StringUtils.isNotBlank(reply.getUser().getHead()))
                if (!reply.getUser().getHead().contains(fileStorageProperties.getBaseUrl()))
                    reply.getUser().setHead(fileStorageProperties.getBaseUrl() + reply.getUser().getHead());
        }

        return BaseResult.ok(replyList,replyCounts);
    }
}
